package cn.com.oceansoft.osc.ms.utils;

import org.apache.commons.lang.StringUtils;
import sun.misc.BASE64Encoder;

import java.security.MessageDigest;
import java.util.Map;

/**
 * @author wuzy
 * @created 2017-03-23-10:18
 * @email wzy@oceansoft.com.cn
 */
public class ExpressEmsPayUtil {
    public String getSortParams(Map<String, String> params) {
        String contnt="";

        for (Map.Entry<String, String> entry : params.entrySet()) {
            if(StringUtils.isBlank(entry.getValue()))
                continue;
            contnt +=  entry.getKey() + entry.getValue();
        }
        return contnt;
    }


    public String sign(String content, String charset) {
        if (charset == null || "".equals(charset)) {
            charset = "UTF-8";
        }
        String sign = "";
        try {
            content = new String(content.getBytes(charset), charset);
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            sun.misc.BASE64Encoder base64Encode = new BASE64Encoder();
            sign = base64Encode.encode(md5.digest(content.getBytes(charset)));

        } catch (Exception e) {
            e.printStackTrace();
        }
        return sign;
    }

}
